package com.dailyblue.java.spring.jwt.handler;

import com.dailyblue.java.spring.jwt.exception.PasswordErrorException;
import com.dailyblue.java.spring.jwt.exception.UsernameNotFoundException;
import com.dailyblue.java.spring.jwt.util.JsonResult;
import com.dailyblue.java.spring.jwt.util.ResultCode;
import com.dailyblue.java.spring.jwt.util.ResultTool;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(value = UsernameNotFoundException.class)
    public JsonResult usernameNotFoundException() {
        return ResultTool.fail(ResultCode.USER_ACCOUNT_NOT_EXIST);
    }

    @ExceptionHandler(PasswordErrorException.class)
    public JsonResult passwordErrorException() {
        return ResultTool.fail(ResultCode.USER_CREDENTIALS_ERROR);
    }

}
